package com.lq.ecoldchain.ui.mine.carInfo.carline.add

import android.arch.lifecycle.MutableLiveData
import com.lq.ecoldchain.base.viewmodel.BaseViewModel
import com.lq.ecoldchain.internet.BaseObserver
import com.lq.ecoldchain.util.toast

/*
*2019/1/2 0002  20:18
*function by lq
*/
class AddLineViewModel : BaseViewModel() {
    val startPlace by lazy { MutableLiveData<String>() }
    val endPlace by lazy { MutableLiveData<String>() }
    val startId by lazy { MutableLiveData<Int>() }
    val endId by lazy { MutableLiveData<Int>() }


    fun add() {
        if (startId.value==null || endId.value ==null) {
            toast { "请先设置起始点与目的地" }
        } else {
            BaseNetCore.ApiServiceImpl.addLine(startId.value!!, endId.value!!).compose(RxTransformer.switchSchedulers()).subscribe(object : BaseObserver<String>() {
                override fun onSuccess(t: String?) {
                    toast { "添加成功" }
                }

                override fun onFail(code: String) {

                }
            })
        }
    }
}